from typing import *
from leetcode.editor.common.node import *


# leetcode submit region begin(Prohibit modification and deletion)
class Solution(object):
    def pivotIndex(self, nums):
        #计算前缀和
        pre_nums = [0] * (len(nums)+1)
        sums =sum(nums)
        for i in range(1,len(pre_nums)):
            pre_nums[i] += pre_nums[i-1] + nums[i-1]
        for i in range(len(pre_nums)-1):
            sums-=nums[i]
            if pre_nums[i] == sums:
                return i
        return -1
# leetcode submit region end(Prohibit modification and deletion)


if __name__ == '__main__':
    solution = Solution()
    print(solution.pivotIndex([1,7,3,6,5,6]))
    # your test code here